using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace LigerUi.MVC.DataModel.EntityClasses.Models.Mapping
{
    public class CF_CompanyMap : EntityTypeConfiguration<CF_Company>
    {
        public CF_CompanyMap()
        {
            // Primary Key
            this.HasKey(t => t.CompanyID);

            // Properties
            this.Property(t => t.CompanyNo)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.CompanyName)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.CompanyAddress)
                .HasMaxLength(100);

            this.Property(t => t.Phone)
                .HasMaxLength(20);

            this.Property(t => t.LegalRepresentative)
                .HasMaxLength(50);

            this.Property(t => t.Fax)
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .HasMaxLength(50);

            this.Property(t => t.WebSite)
                .HasMaxLength(50);

            this.Property(t => t.Remark)
                .HasMaxLength(4000);

            this.Property(t => t.FullPath)
                .HasMaxLength(4000);

            this.Property(t => t.IdentiyNo)
                .HasMaxLength(50);

            this.Property(t => t.RecordStatus)
                .HasMaxLength(20);

            this.Property(t => t.Guid)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.CompanyType)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("CF_Company");
            this.Property(t => t.CompanyID).HasColumnName("CompanyID");
            this.Property(t => t.CompanyNo).HasColumnName("CompanyNo");
            this.Property(t => t.CompanyName).HasColumnName("CompanyName");
            this.Property(t => t.CompanyAddress).HasColumnName("CompanyAddress");
            this.Property(t => t.ParentID).HasColumnName("ParentID");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.LegalRepresentative).HasColumnName("LegalRepresentative");
            this.Property(t => t.Fax).HasColumnName("Fax");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.WebSite).HasColumnName("WebSite");
            this.Property(t => t.Remark).HasColumnName("Remark");
            this.Property(t => t.FullPath).HasColumnName("FullPath");
            this.Property(t => t.IdentiyNo).HasColumnName("IdentiyNo");
            this.Property(t => t.SeqNo).HasColumnName("SeqNo");
            this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
            this.Property(t => t.CreateUserID).HasColumnName("CreateUserID");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");
            this.Property(t => t.ModifyUserID).HasColumnName("ModifyUserID");
            this.Property(t => t.ModifyDate).HasColumnName("ModifyDate");
            this.Property(t => t.Guid).HasColumnName("Guid");
            this.Property(t => t.CompanyType).HasColumnName("CompanyType");

            // Relationships
            this.HasOptional(t => t.CF_Company2)
                .WithMany(t => t.CF_Company1)
                .HasForeignKey(d => d.ParentID);

        }
    }
}
